//
//  KFWNotificationCenterViewController.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/1/16.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//
#undef  UnNotificSelectTextColor
#define UnNotificSelectTextColor RGB(189,189,189)

#undef  NotificSelectTextColor
#define NotificSelectTextColor RGB(91, 165, 229)

#undef  GRNotificSelectViewFrame
#define GRNotificSelectViewFrame CGRectMake(20, _label_notification_wenti.frame.origin.y + _label_notification_wenti.frame.size.height - 4,MainScreenWidth/2 - 40, 4)

#undef  GSNotificSelectViewFrame
#define GSNotificSelectViewFrame CGRectMake(_label_notification_xitong.frame.origin.x + 20, _label_notification_xitong.frame.origin.y + _label_notification_xitong.frame.size.height - 4, MainScreenWidth/2 - 40, 4)


#import "KFWNotificationCenterViewController.h"
#import "RESideMenu.h"
#import "MJRefresh.h"
#import "KFLNotificationProblemRequest.h"
#import "KWLLoginViewController.h"
#import "Model_notificationProblem.h"
#import "Model_notificationSystem.h"
#import "KFWNotificationProblemCell.h"
#import "KFWNotificationProblemCommentCell.h"
#import "KFWNotificationSystemCell.h"
#import "KFLNotificationSystemRequest.h"
#import "KFLRemoveNotificationProblemRequest.h"
#import "MLBlackTransition.h"
#import "KFLRemoveNotificationRequest.h"
#import "KFWMessageViewController.h"
#import "KFWNotificSystemToWebViewController.h"
#import "KWLMyGrewupViewController.h"
#import "KFLRemoveSystemNotificationRequest.h"

@interface KFWNotificationCenterViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>

@property (nonatomic,strong) UITableView *tab_wenti;
@property (nonatomic,strong) UITableView *tab_xitong;
@property (nonatomic,strong) UILabel *label_notification_wenti;
@property (nonatomic,strong) UILabel *label_notification_xitong;
@property NSInteger problemStart;
@property NSInteger systemStart;
@property (nonatomic,strong) NSMutableArray *arr_problemData;
@property (nonatomic,strong) NSMutableArray *arr_systemData;
@property (nonatomic,strong) NSArray *array_location;

@property (nonatomic,strong) UIImageView *imageview_noData;
@property BOOL isNotificationFirst;

@end

@implementation KFWNotificationCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //初始化数据
    _problemStart = 0;
    _systemStart = 0;
    _isNotificationFirst = YES;
    _arr_problemData = [[NSMutableArray alloc] init];
    _arr_systemData = [[NSMutableArray alloc] init];
    _array_location =@[
                       @"北京",@"上海",@"天津",@"重庆",@"黑龙江省",@"吉林省",@"辽宁省",@"河北省",@"山西省",@"内蒙古",@"山东省",@"安徽省",@"江苏省",@"浙江省",@"江西省",@"福建省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西",@"海南省",@"四川省",@"贵州省",@"云南省",@"西藏",@"陕西省",@"甘肃省",@"青海省",@"宁夏",@"新疆",@"香港",@"澳门",@"台湾省"];

    [self ui_title:@"通知中心" withLeftImageName:@"button_back.png" withReftImageName:@"清空已读"];
    self.button_right.frame = CGRectMake(self.view_title_super.frame.size.width - 70, self.button_right.frame.origin.y, 70, 45);
    [self.button_left addTarget:self action:@selector(notificaClickLeftBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.button_right addTarget:self action:@selector(notificaClickRightBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self notificationTopSubViews];
    
    _imageview_noData = [[UIImageView alloc] initWithFrame:CGRectMake((MainScreenWidth - 129)/2, (MainScreenHeight - self.view_title_super.frame.origin.y - self.view_title_super.frame.size.height - 194 - 44)/2 + self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height + 44, 129, 194)];
    _imageview_noData.image = [UIImage imageFileName:@"noNotificationData.png"];
    [self.view addSubview:_imageview_noData];
    
}

- (void)dealloc
{
    _arr_problemData = nil;
    _arr_systemData = nil;
    _array_location = nil;
    _imageview_noData = nil;
    _label_notification_wenti = nil;
    _label_notification_xitong = nil;
    _tab_wenti = nil;
    _tab_xitong = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    if (_isNotificationFirst == YES) {
        _isNotificationFirst = NO;
        [self creatNotificationTab];
        if (_tab_wenti.hidden == NO) {
            [self getNotificationWentiData];
        }
        else if(_tab_xitong.hidden == NO)
        {
            [self getNotificationXitongData];
        }
        
        ///手势
        if(IOS7_VERSION){
            [self.navigationController enabledMLBlackTransition:NO];
        }
        else{
            [self.navigationController_MI setCanDragBack:NO];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//返回上一页
- (void)notificaClickLeftBtn:(id)sender
{
    [self popViewController];
}

//清空已读
- (void)notificaClickRightBtn:(id)sender
{
    KFLRemoveNotificationRequest *request = [[KFLRemoveNotificationRequest alloc] initRequest];
    if (_tab_wenti.hidden == NO) {
        request.string_type = @"0";
    }
    else if(_tab_xitong.hidden == NO)
    {
        request.string_type = @"1";
    }
    else
    {
        return;
    }
    
    [SVProgressHUD showWithStatus:@"删除中..."];
    __weak KFWNotificationCenterViewController *aself = self;
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];
                if (_tab_wenti.hidden == NO) {
                    
                    [_arr_problemData removeAllObjects];
                    [_arr_problemData addObjectsFromArray:result];
                    if(_arr_problemData.count == 0)
                    {
                        _problemStart = 0;
                        _tab_wenti.hidden = YES;
                        _imageview_noData.hidden = NO;
                        [_tab_wenti reloadData];
                    }
                    else
                    {
                        _problemStart = 0 + kCountOfPage;
                        _tab_wenti.hidden = NO;
                        _imageview_noData.hidden = YES;
                        [_tab_wenti reloadData];
                    }
                    _tab_xitong.hidden = YES;
                }
                else if(_tab_xitong.hidden == NO)
                {
                    
                    [_arr_systemData removeAllObjects];
                    [_arr_systemData addObjectsFromArray:result];
                    if(_arr_systemData.count == 0)
                    {
                        _systemStart = 0;
                        _tab_xitong.hidden = YES;
                        _imageview_noData.hidden = NO;
                        [_tab_xitong reloadData];
                    }
                    else
                    {
                        _systemStart = 0 + kCountOfPage;
                        _tab_xitong.hidden = NO;
                        _imageview_noData.hidden = YES;
                        [_tab_xitong reloadData];
                    }
                    _tab_wenti.hidden = YES;
                }
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [aself notificationTokenIsFailure];
            }
                break;
            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];
            }
                break;
        }
        
    }];
}

//创建选项行
- (void)notificationTopSubViews
{
    _label_notification_wenti = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height, MainScreenWidth/2, 44)];
    _label_notification_wenti.userInteractionEnabled = YES;
    _label_notification_wenti.text = @"问题动态";
    _label_notification_wenti.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _label_notification_wenti.textColor = NotificSelectTextColor;
    _label_notification_wenti.textAlignment = NSTextAlignmentCenter;
    _label_notification_wenti.backgroundColor = [UIColor whiteColor];
    _label_notification_wenti.tag = 100;
    CALayer *layer_wenti = [[CALayer alloc] init];
    layer_wenti.borderColor = UnNotificSelectTextColor.CGColor;
    layer_wenti.borderWidth = 0.5;
    layer_wenti.frame = CGRectMake(0, _label_notification_wenti.frame.size.height, _label_notification_wenti.frame.size.width, 0.5);
    [_label_notification_wenti.layer addSublayer:layer_wenti];
    CALayer *layer_wenti_fenge = [[CALayer alloc] init];
    layer_wenti_fenge.borderColor = UnNotificSelectTextColor.CGColor;
    layer_wenti_fenge.borderWidth = 0.5;
    layer_wenti_fenge.frame = CGRectMake(_label_notification_wenti.frame.size.width, 10, 0.5, 24);
    [_label_notification_wenti.layer addSublayer:layer_wenti_fenge];
    
    UITapGestureRecognizer *wentiTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notificationLabelTap:)];
    [_label_notification_wenti addGestureRecognizer:wentiTap];
    [self.view addSubview:_label_notification_wenti];
    
    _label_notification_xitong = [[UILabel alloc] initWithFrame:CGRectMake(_label_notification_wenti.frame.size.width + _label_notification_wenti.frame.origin.x, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height, MainScreenWidth/2, 44)];
    _label_notification_xitong.text = @"系统通知";
    _label_notification_xitong.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _label_notification_xitong.userInteractionEnabled = YES;
    _label_notification_xitong.textColor = UnNotificSelectTextColor;
    _label_notification_xitong.textAlignment = NSTextAlignmentCenter;
    _label_notification_xitong.backgroundColor = [UIColor whiteColor];
    _label_notification_xitong.tag = 101;
    CALayer *layer_xitong = [[CALayer alloc] init];
    layer_xitong.borderColor = UnNotificSelectTextColor.CGColor;
    layer_xitong.borderWidth = 0.5;
    layer_xitong.frame = CGRectMake(0, _label_notification_xitong.frame.size.height, _label_notification_xitong.frame.size.width, 0.5);
    [_label_notification_xitong.layer addSublayer:layer_xitong];
    UITapGestureRecognizer *xitongTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notificationLabelTap:)];
    [_label_notification_xitong addGestureRecognizer:xitongTap];
    [self.view addSubview:_label_notification_xitong];
    
    UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(20, _label_notification_wenti.frame.origin.y + _label_notification_wenti.frame.size.height - 4, MainScreenWidth/2 - 40, 4)];
    view_line.backgroundColor = RGB(91, 165, 229);
    view_line.tag = 102;
    [self.view addSubview:view_line];
    
    UIView *view_zhongjian = [[UIView alloc] initWithFrame:CGRectMake(159, _label_notification_wenti.frame.origin.y + 10, 1, 25)];
    view_zhongjian.backgroundColor = UnNotificSelectTextColor;
    [self.view addSubview:view_zhongjian];
    
    UIView *view_dibu = [[UIView alloc] initWithFrame:CGRectMake(0, view_line.frame.origin.y + view_line.frame.size.height, 320, 1)];
    view_dibu.backgroundColor = RGB(223, 223, 223);
    [self.view addSubview:view_dibu];

}

//创建tab
- (void)creatNotificationTab
{
    _tab_wenti = [[UITableView alloc] initWithFrame:CGRectMake(self.view_title_super.frame.origin.x, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height + 45, self.view_title_super.frame.size.width, self.view.frame.size.height - self.view_title_super.frame.size.height - 45)];
    _tab_wenti.backgroundColor = [UIColor clearColor];
    _tab_wenti.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tab_wenti.delegate = self;
    _tab_wenti.dataSource = self;
    _tab_wenti.tag = 200;
    [self.view addSubview:_tab_wenti];
    
    __weak KFWNotificationCenterViewController *aself = self;
    
    //加入下拉加载更多
    [_tab_wenti addHeaderWithCallback:^{
        aself.problemStart = 0;
        [aself getNotificationWentiData];
    }];
    //加入上拉加载更多
    [_tab_wenti addFooterWithCallback:^{
        [aself getNotificationWentiData];
    }];
    _tab_wenti.hidden = NO;
    
    _tab_xitong = [[UITableView alloc] initWithFrame:CGRectMake(self.view_title_super.frame.origin.x, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height + 45, self.view_title_super.frame.size.width, self.view.frame.size.height - self.view_title_super.frame.size.height - 45)];
    //        tableView_home_other.backgroundColor = RGB(239,239,244);
    _tab_xitong.backgroundColor = [UIColor clearColor];
    _tab_xitong.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tab_xitong.delegate = self;
    _tab_xitong.dataSource = self;
    _tab_xitong.tag = 201;
//    [self.view insertSubview:_tab_xitong atIndex:1];
    [self.view addSubview:_tab_xitong];
    //下拉刷新
    [_tab_xitong addHeaderWithCallback:^{
        aself.systemStart = 0;
        [aself getNotificationXitongData];
    }];
    
    //加入上拉加在更多
    [_tab_xitong addFooterWithCallback:^{
        [aself getNotificationXitongData];
    }];
    _tab_xitong.hidden = YES;
}

- (void)notificationLabelTap:(UIGestureRecognizer *)tap{
    UILabel *lab = (UILabel *)tap.view;
    switch (lab.tag){
        case 100:
        {
            if (![lab.textColor isEqual:NotificSelectTextColor])
            {
                _problemStart = 0;
                [self getNotificationWentiData];
                
                UIView *aview = [self.view viewWithTag:102];
                [UIView animateWithDuration:0.2 animations:^{
                    _label_notification_wenti.textColor = NotificSelectTextColor;
                    _label_notification_xitong.textColor = UnNotificSelectTextColor;
                    aview.frame = GRNotificSelectViewFrame;
                }];
            }
        }break;
        case 101:
        {
            if (![lab.textColor isEqual:NotificSelectTextColor])
            {
                _systemStart = 0;
                [self getNotificationXitongData];
                
                UIView *aview = [self.view viewWithTag:102];
                [UIView animateWithDuration:0.2 animations:^{
                    _label_notification_wenti.textColor = UnNotificSelectTextColor;
                    _label_notification_xitong.textColor = NotificSelectTextColor;
                    aview.frame = GSNotificSelectViewFrame;
                }];
            }
        }break;
        default:
            break;
    }
}

//取问题列表
- (void)getNotificationWentiData
{
    [SVProgressHUD showWithStatus:@"加载中..."];
    KFLNotificationProblemRequest *request = [[KFLNotificationProblemRequest alloc] initRequest];
    request.notificationProblem_startNum = [NSString stringWithFormat:@"%ld",(long)_problemStart];
    request.notificationProblem_displaynum = [NSString stringWithFormat:@"%d",kCountOfPage];
    
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        
        [_tab_wenti headerEndRefreshing];
        [_tab_wenti footerEndRefreshing];
        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];

                if (_problemStart == 0) {
                    [_arr_problemData removeAllObjects];
                }
                _problemStart = _problemStart + kCountOfPage;
                [_arr_problemData addObjectsFromArray:result];
                if(_arr_problemData.count == 0)
                {
                    _tab_wenti.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_wenti.hidden = NO;
                    _imageview_noData.hidden = YES;
                    [_tab_wenti reloadData];

                }
                _tab_xitong.hidden = YES;
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [self notificationTokenIsFailure];
            }
                break;
            case 10009:
            {
//                NSString *msg = [result objectAtIndex:0];
//                [SVProgressHUD dismissWithSuccess:msg afterDelay:1.5];
                [SVProgressHUD dismiss];
                if(_arr_problemData.count == 0)
                {
                    _tab_wenti.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_wenti.hidden = NO;
                    _imageview_noData.hidden = YES;
                }
                _tab_xitong.hidden = YES;
            }
                break;

            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];
                if(_arr_problemData.count == 0)
                {
                    _tab_wenti.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_wenti.hidden = NO;
                    _imageview_noData.hidden = YES;
                }
                _tab_xitong.hidden = YES;

            }
                break;
        }
    }];
}

//取系统列表
- (void)getNotificationXitongData
{
    [SVProgressHUD showWithStatus:@"加载中..."];
    KFLNotificationSystemRequest *request = [[KFLNotificationSystemRequest alloc] initRequest];
    request.notificationSystem_startNum = [NSString stringWithFormat:@"%ld",(long)_systemStart];
    request.notificationSystem_displaynum = [NSString stringWithFormat:@"%d",kCountOfPage];
    
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        [_tab_xitong headerEndRefreshing];
        [_tab_xitong footerEndRefreshing];
        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];
                
                if (_systemStart == 0) {
                    [_arr_systemData removeAllObjects];
                }
                _systemStart = _systemStart + kCountOfPage;
                [_arr_systemData addObjectsFromArray:result];
                if(_arr_systemData.count == 0)
                {
                    _tab_xitong.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_xitong.hidden = NO;
                    _imageview_noData.hidden = YES;
                    [_tab_xitong reloadData];
                    
                }
                _tab_wenti.hidden = YES;
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [self notificationTokenIsFailure];
            }
                break;
            case 10009:
            {
//                NSString *msg = [result objectAtIndex:0];
//                [SVProgressHUD dismissWithSuccess:msg afterDelay:1.5];
                [SVProgressHUD dismiss];

                if(_arr_systemData.count == 0)
                {
                    _tab_xitong.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_xitong.hidden = NO;
                    _imageview_noData.hidden = YES;
                }
                _tab_wenti.hidden = YES;
            }
                break;
                
            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];
                if(_arr_systemData.count == 0)
                {
                    _tab_xitong.hidden = YES;
                    _imageview_noData.hidden = NO;
                }
                else
                {
                    _tab_xitong.hidden = NO;
                    _imageview_noData.hidden = YES;
                }
                _tab_wenti.hidden = YES;
                
            }
                break;
        }
    }];

}

//用户已在其他地方登陆
- (void)notificationTokenIsFailure{
    UIAlertView *alter_login;
    if(IOS8_VERSION){
        alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    else{
        alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    alter_login.tag = 10003;
    [alter_login show];
}

#pragma mark - 更新系统跳转成长的动态未读数
- (void)updateSystemUnreadWith:(NSString *)n_id
{
    KFLRemoveSystemNotificationRequest *request = [[KFLRemoveSystemNotificationRequest alloc] initRequest];
    request.n_id = n_id;
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:
            {}
                break;
            default:
                break;
        }
    }];

}


#pragma mark - 删除单条问题动态 -
- (void)deletOneProblemNotification:(NSIndexPath *)index
{
    [SVProgressHUD showWithStatus:@"加载中..."];

    KFLRemoveNotificationProblemRequest *request = [[KFLRemoveNotificationProblemRequest alloc] initRequest];
    id obje = [_arr_problemData objectAtIndex:index.row];
    if ([obje isKindOfClass:[Model_notificationProblem class]]) {
        Model_notificationProblem *problem = (Model_notificationProblem *)obje;
        request.n_id = problem.string_id;
    }
    else
    {
        Model_notificationProblemComments *problemComment = (Model_notificationProblemComments *)obje;
        request.n_id = problemComment.string_id;
    }
    
    __weak KFWNotificationCenterViewController *aself = self;
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];
                [aself.arr_problemData removeObjectAtIndex:index.row];
                [aself.tab_wenti deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade];
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [self notificationTokenIsFailure];
            }
                break;
            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];
            }
                break;
        }
    }];
}
#pragma mark - AlertView -
/**
 *  账号被替换下线
 */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
        case 10003:{
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;
        default:
            break;
    }
}

#pragma mark - UITableViewDelegate -

/**
 *  列表数据源
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == _tab_wenti) {
        return _arr_problemData.count;
    }
    else
    {
        return _arr_systemData.count;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ProblemCellIdentifier = @"ProblemCellIdentifier";
    static NSString *ProblemCommentCellIdentifier = @"ProblemCommentCellIdentifier";
    static NSString *SystemCellIdentifier = @"SystemCellIdentifier";

    KFWNotificationProblemCell *problemCell = [tableView dequeueReusableCellWithIdentifier:ProblemCellIdentifier];
    KFWNotificationProblemCommentCell *problemCommentCell = [tableView dequeueReusableCellWithIdentifier:ProblemCommentCellIdentifier];
    KFWNotificationSystemCell *systemCell = [tableView dequeueReusableCellWithIdentifier:SystemCellIdentifier];

    if (tableView == _tab_wenti) {
        id obje = [_arr_problemData objectAtIndex:indexPath.row];
        if ([obje isKindOfClass:[Model_notificationProblem class]]) {
            if (problemCell == nil)
            {
                problemCell = [[KFWNotificationProblemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ProblemCellIdentifier];
            }
            
            Model_notificationProblem *problem = (Model_notificationProblem *)obje;
            
            NSInteger kind_area = problem.string_question_area.integerValue;
            problemCell.label_name.text = [NSString stringWithFormat:@"%@网友 追问了你",_array_location[kind_area]];
            [problemCell changeNotiProblemCellWith:problem];
            return problemCell;
        }
        else
        {
            if (problemCommentCell == nil)
            {
                problemCommentCell = [[KFWNotificationProblemCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ProblemCommentCellIdentifier];
            }

            Model_notificationProblemComments *problemComment = (Model_notificationProblemComments *)obje;
            
            NSInteger kind_area = problemComment.string_question_area.integerValue;
            problemCommentCell.label_name.text = [NSString stringWithFormat:@"%@网友 评价了你",_array_location[kind_area]];
            [problemCommentCell changeNotiProblemCommentCellWith:problemComment];
            
            return problemCommentCell;
        }
    }
    else
    {
        
        if (systemCell == nil) {
            systemCell = [[KFWNotificationSystemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SystemCellIdentifier];
        }
        Model_notificationSystem *system = [_arr_systemData objectAtIndex:indexPath.row];
        [systemCell changeNotificationSystemCellWith:system];
        
        return systemCell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _tab_wenti) {
        id obje = [_arr_problemData objectAtIndex:indexPath.row];
        if ([obje isKindOfClass:[Model_notificationProblem class]]) {
            Model_notificationProblem *problem = (Model_notificationProblem *)obje;
            return problem.pheight;
        }
        else if([obje isKindOfClass:[Model_notificationProblemComments class]])
        {
            Model_notificationProblemComments *problemComment = (Model_notificationProblemComments *)obje;
            return problemComment.pCheight;
        }
        else
        {
            return 0;
        }
    }
    else
    {
        Model_notificationSystem *system = [_arr_systemData objectAtIndex:indexPath.row];
        return system.nSHeight;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _tab_wenti) {
        id obje = [_arr_problemData objectAtIndex:indexPath.row];
        NSString *question_id = nil;
        if ([obje isKindOfClass:[Model_notificationProblem class]]) {
            Model_notificationProblem *problem = (Model_notificationProblem *)obje;
            question_id = problem.string_question_id;
            if (problem.string_isunread.integerValue == 1) {
                problem.string_isunread = @"0";
                
                KFWNotificationProblemCell *problemCell = (KFWNotificationProblemCell *)[_tab_wenti cellForRowAtIndexPath:indexPath];
                problemCell.imageview_unread.hidden = YES;
            }
        }
        else
        {
            Model_notificationProblemComments *problemComment = (Model_notificationProblemComments *)obje;
            question_id = problemComment.string_question_id;
            if (problemComment.string_isunread.integerValue == 1) {
                problemComment.string_isunread = @"0";
                KFWNotificationProblemCommentCell *problemCommentCell= (KFWNotificationProblemCommentCell *)[_tab_wenti cellForRowAtIndexPath:indexPath];
                problemCommentCell.imageview_unread.hidden = YES;
            }
            
        }
        
        KFWMessageViewController *messageVC = [[KFWMessageViewController alloc] initWithQID:question_id andUpdataUnread:YES];
        [self pushViewController:messageVC];
    }
    else
    {
        Model_notificationSystem *system = [_arr_systemData objectAtIndex:indexPath.row];
        
        if([system.string_automatic integerValue] == 1) //后台发布的通知跳转网页
        {
            if (system.string_link && system.string_link.length > 0) {
                KFWNotificSystemToWebViewController *control = [[KFWNotificSystemToWebViewController alloc] initNotificSystemToWebWithUrlStr:system.string_link andUnreadnum:[system.string_isunread integerValue] andSystemNotificID:system.string_id];
                [self pushViewController:control];
            }
        }
        else if([system.string_automatic integerValue] == 2) //升级推送跳转我的成长
        {
            [self updateSystemUnreadWith:system.string_id];
            
            KWLMyGrewupViewController *control = [[KWLMyGrewupViewController alloc] initWithGrewupLeftBtnType:KFWGrewupLeftBtnBackType andModel:KFWGrewupModelTypeMyLevel];
            [self pushViewController:control];

        }
        else if([system.string_automatic integerValue] == 3) //获得勋章跳转我的成长
        {
            [self updateSystemUnreadWith:system.string_id];

            KWLMyGrewupViewController *control = [[KWLMyGrewupViewController alloc] initWithGrewupLeftBtnType:KFWGrewupLeftBtnBackType andModel:KFWGrewupModelTypeMyMedal];
            [self pushViewController:control];
        }

        system.string_isunread = @"0";
        KFWNotificationSystemCell *cell = (KFWNotificationSystemCell *)[_tab_xitong cellForRowAtIndexPath:indexPath];
        cell.label_content.textColor = RGB(162, 162, 162);
        cell.label_title.textColor = RGB(162, 162, 162);
    }
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _tab_wenti) {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self deletOneProblemNotification:indexPath];
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{
    return UITableViewCellEditingStyleDelete;
}

/*改变删除按钮的title*/
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

@end
